package com.gustavo.sistema.service;

import java.util.List;

import javax.inject.Inject;

import com.gustavo.sistema.dao.ErroDeBancoDeDados;
import com.gustavo.sistema.dao.jdbc.ClienteDaoJdbc;
import com.gustavo.sistema.model.Cliente;

public class ClienteService extends Service{
	
	@Inject
	private ClienteDaoJdbc clienteDaoJdbc;
	
	public void inserir(Cliente cliente) throws ErroNaFaseService{
		
		try {
			beginTransaction();
			
			clienteDaoJdbc.inserirCliente(cliente);
						
			commitTransaction();
		
		} catch (ErroDeBancoDeDados e) {
			rollbackTransaction();
			throw new ErroNaFaseService(e);
		}
	}
		
	public void atualizar(Cliente cliente) throws ErroNaFaseService{
		
		try {
			beginTransaction();
			
			clienteDaoJdbc.atualizarCliente(cliente);
						
			commitTransaction();
		
		} catch (ErroDeBancoDeDados e) {
			rollbackTransaction();
			throw new ErroNaFaseService(e);
		}
	}
		
	public void excluir(Integer id) throws ErroNaFaseService{
		
		try {
			beginTransaction();
			
			clienteDaoJdbc.excluirCliente(id);
						
			commitTransaction();
		
		} catch (ErroDeBancoDeDados e) {
			rollbackTransaction();
			throw new ErroNaFaseService(e);
		}
	}
		
	public List<Cliente> listarClientes() throws ErroNaFaseService {

		try {
			return clienteDaoJdbc.listarClientes();

		} catch (ErroDeBancoDeDados e) {
			rollbackTransaction();
			throw new ErroNaFaseService(e);
		}
	}

}
